package com.jzh.eurekaclient.web;

import com.jzh.eurekaclient.util.NetworkUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class ComputeController {
    private static final Logger logger = LogManager.getLogger(ComputeController.class);
    @RequestMapping("/hello")
    public String index() {
        return "Hello World";
    }

    @RequestMapping(value = "/add" ,method = RequestMethod.GET)
    public Integer add(HttpServletRequest request, @RequestParam Integer a, @RequestParam Integer b) throws Exception{
        Integer r = a + b;
        logger.info("/add, host:" + NetworkUtil.getIpAddress(request) + ", result:" + r);
        return r;
    }
}
